/**
 * Copyright 2013 ABSir's Studio
 * 
 * All right reserved
 *
 * Create on 2013-7-29 上午11:08:36
 */
package com.absir.android.app;

import android.content.ContentProvider;

import com.absir.android.context.ContextUtils;
import com.absir.bean.core.BeanFactoryUtils;
import com.absir.bean.inject.InjectInvoker;

/**
 * @author absir
 * 
 */
public abstract class ProviderBean extends ContentProvider {

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.content.ContentProvider#onCreate()
	 */
	@Override
	public final boolean onCreate() {
		// TODO Auto-generated method stub
		try {
			InjectInvoker[][] injectInvokers = ContextUtils.getCreateInvokers(getClass());
			for (InjectInvoker injectInvoker : injectInvokers[0]) {
				injectInvoker.invoke(BeanFactoryUtils.get(), this);
			}

			boolean onCreate = onCreateBean();
			BeanFactoryUtils.onCreate(this);
			for (InjectInvoker injectInvoker : injectInvokers[1]) {
				injectInvoker.invoke(BeanFactoryUtils.get(), this);
			}

			return onCreate;

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}

		return false;
	}

	protected abstract boolean onCreateBean();

}
